package org.jeecg.modules.xmss.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.xmss.entity.XmssIdea;
import org.jeecg.modules.xmss.entity.XmssSupervise;

import java.util.List;

/**
 * @Description: 意见督办关系表
 * @Author: jeecg-boot
 * @Date:   2020-09-18
 * @Version: V1.0
 */
public interface XmssSuperviseMapper extends BaseMapper<XmssSupervise> {

    @Select("<script>"
            +"SELECT realname from sys_user where  type=#{type} and  id in  (select user_id from xmss_supervise where idea_id=#{id} )"
            + "<if test='ids!=null'>"
            + "and rel_tenant_ids=#{ids}"
            + "</if>"
            + "</script>")
    List<String> getByIds( @Param("id") String id, @Param("ids") String ids,String type);

    @Select("<script>"
            +"SELECT id from sys_user where  type=#{type} and  id in  (select assign_user_id from xmss_supervise where idea_id=#{id} )"
            + "<if test='ids!=null'>"
            + "and rel_tenant_ids=#{ids}"
            + "</if>"
            + "</script>")
    List<String> getByIdse( @Param("id") String id, @Param("ids") String ids,String type);



    @Select("select user_id from xmss_supervise where idea_id=#{ideaId} and user_Id=#{userId}")
    List<XmssSupervise> selectId( @Param("ideaId") String ideaId,@Param("userId") String userId);


    @Select("select * from sys_user where  id=#{userId}")
    SysUser selectUserId(@Param("userId") String userId);


    @Select("select * from xmss_supervise where idea_id=#{ideaId}    ORDER BY create_time LIMIT 1")
    List<XmssSupervise> selectByIds( @Param("ideaId") String ideaId);

    @Select("select realname from sys_user where id in (select user_id from xmss_supervise where idea_id =#{ideaId} )")
    List<String> selectDbNameByIdeaId( @Param("ideaId") String ideaId);

    @Select("select avatar from sys_user where avatar is not null and avatar!='' and id in (select user_id from xmss_supervise where idea_id =#{ideaId} )")
    List<SysUser> selectDbPictureByIdeaId(@Param("ideaId") String ideaId);

    @Select("select * from sys_user where avatar is not null and avatar!='' and id in (select assign_user_id from xmss_supervise where idea_id =#{ideaId} )")
    List<SysUser> selectJbPictureByIdeaId(@Param("ideaId") String ideaId);

    @Select("delete from xmss_supervise where user_id=#{userId} and idea_id=#{ideaId}")
    void deleteDbAndIdea(@Param("userId") String userId,@Param("ideaId") String ideaId);

    @Select("delete from xmss_supervise where assign_user_id=#{userId} and idea_id=#{ideaId}")
    void deleteJbAndIdea(@Param("userId") String userId,@Param("ideaId") String ideaId);

    @Select("<script>"
            +"SELECT id from sys_user where  type=#{type} and  id in  (select user_id from xmss_supervise where idea_id=#{id} )"
            + "<if test='ids!=null'>"
            + "and rel_tenant_ids=#{ids}"
            + "</if>"
            + "</script>")
    List<String> getById( @Param("id") String id, @Param("ids") String ids,String type);


    @Select("<script>"
            +"SELECT realname from sys_user where  type=#{type} and  id in  (select assign_user_id from xmss_supervise where idea_id=#{id} )"
            + "<if test='ids!=null'>"
            + "and rel_tenant_ids=#{ids}"
            + "</if>"
            + "</script>")
    List<String> getByIde( @Param("id") String id, @Param("ids") String ids,String type);
}
